package com.jcl.recruit.resume.mapper;

import com.jcl.recruit.mapper.SqlMapper;
import com.jcl.recruit.mapper.provider.SqlProvider;
import com.jcl.recruit.resume.model.ResumeBasicInfo;
import com.jcl.recruit.resume.provider.ResumeBasicInfoSqlProvider;
import org.apache.ibatis.annotations.*;

import java.util.List;
import java.util.Map;

/**
 * @author liuyy
 * @date 2018/11/17
 */
public interface ResumeBasicInfoMapper extends SqlMapper {

    String TABLE_NAME = "resume_basic_info";
    String SQL_QUERY_ALL = "select * from resume_basic_info where corp_code = #{corpCode}";
    String SQL_QUERY_ID = "select * from resume_basic_info where id ";
    String SQL_DELETE_ID = "delete from resume_basic_info where id = #{id}";

    String SQL_ORDER_UPDATE_DATE_DESC = " order by update_date desc ";

    @Select({
            QUERY_SCRIPT_START,
            SQL_QUERY_ALL,
            SQL_ORDER_UPDATE_DATE_DESC,
            QUERY_SCRIPT_END
    })
    List<Map<String, Object>> findAllMap(@Param("corpCode") String corpCode);

    @Select({
            QUERY_SCRIPT_START,
            SQL_QUERY_ALL,
            SQL_ORDER_UPDATE_DATE_DESC,
            QUERY_SCRIPT_END
    })
    List<ResumeBasicInfo> findAll(@Param("corpCode") String corpCode);

    @Select({
            QUERY_SCRIPT_START,
            SQL_QUERY_ID,
            SQL_IN,
            FOREACH_START_LIST_IDS,
            SQL_PROPERTY_ID_VALUE,
            FOREACH_END,
            SQL_ORDER_UPDATE_DATE_DESC,
            QUERY_SCRIPT_END
    })
    List<ResumeBasicInfo> findList(@Param("ids") List<Integer> ids);

    @Select({
            QUERY_SCRIPT_START,
            SQL_QUERY_ID,
            SQL_EQUAL,
            SQL_PROPERTY_ID_VALUE,
            QUERY_SCRIPT_END
    })
    Map<String, Object> findOneMap(@Param("id") Integer id);

    @Select({
            QUERY_SCRIPT_START,
            SQL_QUERY_ID,
            SQL_EQUAL,
            SQL_PROPERTY_ID_VALUE,
            QUERY_SCRIPT_END
    })
    ResumeBasicInfo findOne(@Param("id") Integer id);

    @Select({
            QUERY_SCRIPT_START,
            SQL_QUERY_ALL,
            SQL_AND,
            "apply_other_jid = #{externalKey} ",
            QUERY_SCRIPT_END
    })
    ResumeBasicInfo findOneByExternalKey(@Param("corpCode") String corpCode,
                                         @Param("externalKey") String externalKey);

    @InsertProvider(type = ResumeBasicInfoSqlProvider.class, method = SqlProvider.SQL_METHOD_INSERT)
    @Options(useGeneratedKeys = true, keyProperty = "id")
    int add(ResumeBasicInfo entity);

    @UpdateProvider(type = ResumeBasicInfoSqlProvider.class, method = SqlProvider.SQL_METHOD_UPDATE)
    int update(ResumeBasicInfo entity);

    @Delete({SQL_DELETE_ID})
    int delete(@Param("id") Integer id);
}
